package com.bbex.mapper;

import com.bbex.entity.SourceAddress;
import com.bbex.sql.build.SourceAddressSqlBuild;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface SourceAddressDao {

    @InsertProvider(type = SourceAddressSqlBuild.class, method = "insert")
    long insert(SourceAddress sourceAddress);

    @SelectProvider(type = SourceAddressSqlBuild.class, method = "findById")
    SourceAddress findById(String id);

    @UpdateProvider(type = SourceAddressSqlBuild.class, method = "updateById")
    long updateById(SourceAddress sourceAddress);


    @Select("select " + SourceAddressSqlBuild.columns + " from js_plat_user_source_address where user_id =#{userId} and coin_symbol = #{coinSymbol} limit 1")
    SourceAddress findByUserIdAndCoinSymbol(@Param("userId") String userId, @Param("coinSymbol") String coinSymbol);

    @Select("select " + SourceAddressSqlBuild.columns + " from js_plat_user_source_address where address =#{address} limit 1")
    SourceAddress findByAddress(@Param("address") String address);

    @Select("select count(*) from js_plat_user_source_address where address =#{address} and status = 1 limit 1")
    long count(@Param("address") String address);

    @Select("select " + SourceAddressSqlBuild.columns + " from js_plat_user_source_address where user_id =#{userId} and coin_type = #{coinType} order by create_date desc")
    List<SourceAddress> listByUserIdAndCoinType(@Param("userId") String userId, @Param("coinType") String coinType);

    @Select("select address from js_plat_user_source_address where coin_type = #{coinType}")
    List<String> listAddressByCoinType(@Param("coinType") String coinType);

    @Delete("delete from js_plat_user_source_address where id = #{id}")
    long delete(@Param("id") String id);

    @Select("select " + SourceAddressSqlBuild.columns + " from js_plat_user_source_address where user_id =#{userId} and coin_type = #{coinType} order by create_date desc limit 1")
    SourceAddress findLastest(String userId, String coinType);
}
